package com.focusai.efairy.model.request;

import com.focusai.efairy.model.base.UpLoadBaseEntity;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.PutPureJSONRequest;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

/**
 * Created by luo_guangwen on 2017/8/13.
 */

public class PutPasswdRequest extends PutPureJSONRequest<String> {
    private UpLoadEntity entity;

    public PutPasswdRequest(String oldPasswd, String newPasswd, Response.Listener<String> listener) {
        super(UrlUtils.createUrl("/appapi/password"), listener);
        entity = new UpLoadEntity();
        entity.efairyuser_password_old = oldPasswd;
        entity.efairyuser_password_new = newPasswd;
    }

    @Override
    protected String parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<String>() {
        }.getType());
    }

    @Override
    public String getPureJSON() throws JSONException {
        if (entity != null) {
            return GsonHelper.getInstance().toJson(entity);
        }
        return null;
    }

    static class UpLoadEntity extends UpLoadBaseEntity {
        String efairyuser_password_old;
        String efairyuser_password_new;
    }
}
